﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SchoolRoleGroupManage.aspx.cs" Inherits="Educational_School_SchoolRoleGroupManage" %>
<script type="text/javascript">
window.addEvent('domready',function(){
    var schoolRoleGroup={};
    
    schoolRoleGroup.deleteSchoolRoleGroup=function(){
        var indices = schoolRoleGroup.datagrid.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    if (indices.length > 1)
	    {
		    MUI.showModalAlert('修改时不允许一次修改多行数据。。');
		    return;
	    }
	    var selectedData=schoolRoleGroup.datagrid.getDataByRow(indices[0]);
        MUI.showConfirm("你确认删除这个权限组么？请确保此权限组没有与之相关职位。此操作不可恢复！",function(){
            MUI.showModalMessage('正在删除权限组');
            new Request.JSON({url:'../Ajax/SchoolRoleGroupManage.aspx?Action=deleteSchoolRoleGroup&schoolRoleGroupId='+selectedData.roleGroupId,noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    MUI.appendStatusMessage({'text':result.msg});
                    schoolRoleGroup.datagrid.loadData();
                }
            },onFailure:function(error){
                MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
                MUI.hideModalMessage();
            }}).get();
        });
    };
    
    schoolRoleGroup.addFormCheck=function(){
        new FormCheck('formAddForSchoolRoleGroup',{display:{tipsSchoolRoleGroup:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在添加权限组');
            new Request.JSON({url:'../Ajax/SchoolRoleGroupManage.aspx?Action=saveAddSchoolRoleGroup',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowAddForSchoolRoleGroup').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    schoolRoleGroup.datagrid.options.page=1;
                    schoolRoleGroup.datagrid.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formAddForSchoolRoleGroup'));
        }});   
    };
    
    schoolRoleGroup.showAddForm=function(){
        MUI.showModalMessage('正在读取权限组');
        new Request.JSON({url:'../Ajax/SchoolRoleManage.aspx?Action=search',noCache:true,onSuccess:function(result){
            MUI.hideModalMessage();
            if(result.error)
                MUI.appendStatusMessage({'text':result.msg});
            else
            {
                var data=result.data;
                var ul=$('schoolRoleGroupAddTabs');
                var content=$('schoolRoleGroupAddTabsContent');
                var html='',html2='';
                for(var i=0;i<data.length;i++)
                {
                    if(i==0)
                    {
                        html+='<li class="selected"><a href="schoolRoleGroupAddTabsContent'+i.toString()+'" title="'+data[i].categoryName+'">'+data[i].categoryName+'</a></li>';
                        html2+='<div id="schoolRoleGroupAddTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;">';
                    }
                    else
                    {
                        html+='<li><a href="schoolRoleGroupAddTabsContent'+i.toString()+'" title="'+data[i].categoryName+'">'+data[i].categoryName+'</a></li>';
                        html2+='<div id="schoolRoleGroupAddTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;display:none;">';
                    }
                    html2+='<input type="checkbox" onclick="if(this.checked){$(\'schoolRoleGroupAddTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',true);}else{$(\'schoolRoleGroupAddTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',false);}" /><span style="margin:0 15px 0 3px;">选择该组所有权限</span><br/>'
                    for(var j=0;j<data[i].schoolRoles.length;j++)
                    {
                        if(j>0&&j%4==0)
                            html2+='<br />';
                        html2+='<input type="checkbox" name="roleIds" value="'+data[i].schoolRoles[j].roleId+'" />';
                        html2+='<span style="margin:0 15px 0 3px;">'+data[i].schoolRoles[j].roleName+'</span>';
                    }
                    html2+='</div>';
                    ul.set('html',html);
                    content.set('html',html2);
                    MochaUI.initializeTabs('schoolRoleGroupAddTabs', 'schoolRoleGroupAddTabsContent');
                }
            }
        },onFailure:function(error){
	        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
	        MUI.hideModalMessage();
        }}).get();
        MUI.openContentByWindow('windowAddForSchoolRoleGroup','添加权限组',$('formContainerForSchoolRoleGroup'),$('formAddForSchoolRoleGroup'),400,240);
    };
    
    schoolRoleGroup.updateFormCheck=function(){
        new FormCheck('formUpdateForSchoolRoleGroup',{display:{tipsSchoolRoleGroup:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在修改权限组');
            new Request.JSON({url:'../Ajax/SchoolRoleGroupManage.aspx?Action=saveUpdateSchoolRoleGroup',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowUpdateForSchoolRoleGroup').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    schoolRoleGroup.datagrid.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formUpdateForSchoolRoleGroup'));
        }});   
    };
    
    schoolRoleGroup.showUpdateForm=function(){
        var indices = schoolRoleGroup.datagrid.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    if (indices.length > 1)
	    {
		    MUI.showModalAlert('修改时不允许一次修改多行数据。。');
		    return;
	    }
	    var selectedData=schoolRoleGroup.datagrid.getDataByRow(indices[0]);
	    var element=$('formUpdateForSchoolRoleGroup');
	    element.getElement('input[name=schoolRoleGroupId]').set('value',selectedData.roleGroupId);
	    element.getElement('input[name=schoolRoleGroupName]').set('value',selectedData.roleGroupName);
        MUI.showModalMessage('正在读取权限组');
        new Request.JSON({url:'../Ajax/SchoolRoleManage.aspx?Action=search',noCache:true,onSuccess:function(result){
            MUI.hideModalMessage();
            if(result.error)
                MUI.appendStatusMessage({'text':result.msg});
            else
            {
                var data=result.data;
                var ul=$('schoolRoleGroupUpdateTabs');
                var content=$('schoolRoleGroupUpdateTabsContent');
                var html='',html2='';
                var i=0,j=0,k=0;
                for(i=0;i<data.length;i++)
                {
                    if(i==0)
                    {
                        html+='<li class="selected"><a href="schoolRoleGroupUpdateTabsContent'+i.toString()+'" title="'+data[i].categoryName+'">'+data[i].categoryName+'</a></li>';
                        html2+='<div id="schoolRoleGroupUpdateTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;">';
                    }
                    else
                    {
                        html+='<li><a href="schoolRoleGroupUpdateTabsContent'+i.toString()+'" title="'+data[i].categoryName+'">'+data[i].categoryName+'</a></li>';
                        html2+='<div id="schoolRoleGroupUpdateTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;display:none;">';
                    }
                    html2+='<input type="checkbox" onclick="if(this.checked){$(\'schoolRoleGroupUpdateTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',true);}else{$(\'schoolRoleGroupUpdateTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',false);}" /><span style="margin:0 15px 0 3px;">选择该组所有权限</span><br/>'
                    for(j=0;j<data[i].schoolRoles.length;j++)
                    {
                        if(j>0&&j%4==0)
                            html2+='<br />';
                        html2+='<input type="checkbox" name="roleIds" value="'+data[i].schoolRoles[j].roleId+'"';
                        for(k=0;k<selectedData.roles.length;k++)
                        {
                            if(selectedData.roles[k].roleId==data[i].schoolRoles[j].roleId)
                                html2+=' checked';
                        }
                        html2+=' />';
                        html2+='<span style="margin:0 15px 0 3px;">'+data[i].schoolRoles[j].roleName+'</span>';
                    }
                    html2+='</div>';
                    ul.set('html',html);
                    content.set('html',html2);
                    MochaUI.initializeTabs('schoolRoleGroupUpdateTabs', 'schoolRoleGroupUpdateTabsContent');
                }
            }
        },onFailure:function(error){
	        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
	        MUI.hideModalMessage();
        }}).get();
        MUI.openContentByWindow('windowUpdateForSchoolRoleGroup','添加权限组',$('formContainerForSchoolRoleGroup'),$('formUpdateForSchoolRoleGroup'),400,240);
    };
   
    schoolRoleGroup.loadData=function(){
	    schoolRoleGroup.datagrid = new omniGrid('dataListForSchoolRoleGroup', {
            columnModel: [
                {header: '权限组ID',dataIndex: 'roleGroupId',dataType:'number',width:80,sortable:true},
                {header: '权限组名称',dataIndex: 'roleGroupName',dataType:'string',width:120,sortable:true},
                {header: '所拥有的权限',dataIndex: 'roleGroupId',dataType:'number',width:500,sortable:false,labelFunction:function(rowdata, r, columnModel){
                    var temp='';
                    for(var i=0;i<rowdata.roles.length;i++)
                    {
                        temp+=rowdata.roles[i].roleName+',';
                    }
                    temp+='&nbsp;';
                    return temp;
                }}
            ],
            buttons : [
                {name: '添加', bclass: 'add', onclick : schoolRoleGroup.showAddForm},
                {name: '修改', bclass: 'update', onclick : schoolRoleGroup.showUpdateForm},
                {name: '删除', bclass: 'delete', onclick : schoolRoleGroup.deleteSchoolRoleGroup}
            ],
            url:'../Ajax/SchoolRoleGroupManage.aspx?Action=search',
            height:$('dataListForSchoolRoleGroup').getParent().getParent().getStyle('height').toInt(),
            serverSort:false,
            multipleSelection:false,
            sortHeader:true,
            pagination:false
        });
    };
    
    schoolRoleGroup.binddingEvent=function(){
    };
    
    schoolRoleGroup.initialize=function(){
        new ZebraTable({elements:'table.tableFixed'});
        schoolRoleGroup.loadData();
        schoolRoleGroup.binddingEvent();
        schoolRoleGroup.addFormCheck();
        schoolRoleGroup.updateFormCheck();
    };
    
    schoolRoleGroup.init=function(){
        schoolRoleGroup.initialize();
    };
    
    schoolRoleGroup.init();
});
</script>
<div id="dataListForSchoolRoleGroup"></div>

<!--隐藏的表单-->
<div id="formContainerForSchoolRoleGroup" style="display:none;">
<!--添加表单-->
<form id="formAddForSchoolRoleGroup">
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">权限组名：</td>
        <td class="tableLeft2"><input type="text" class="input" name="schoolRoleGroupName" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交添加" /></td>
    </tr>
</table>
<div class="toolbarTabs">
    <ul id="schoolRoleGroupAddTabs" class="tab-menu">
	</ul>
	<div class="clear"></div>
</div>
<div id="schoolRoleGroupAddTabsContent" style="padding:0px 5px 0px 5px;"></div>
</form>
<!--修改表单-->
<form id="formUpdateForSchoolRoleGroup">
<input type="hidden" name="schoolRoleGroupId" />
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">权限组名：</td>
        <td class="tableLeft2"><input type="text" class="input" name="schoolRoleGroupName" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交修改" /></td>
    </tr>
</table>
<div class="toolbarTabs">
    <ul id="schoolRoleGroupUpdateTabs" class="tab-menu">
	</ul>
	<div class="clear"></div>
</div>
<div id="schoolRoleGroupUpdateTabsContent" style="padding:0px 5px 0px 5px;"></div>
</form>
</div>
